﻿#define _CRT_SECURE_NO_WARNINGS 1
#pragma once

844. 比较含退格的字符串
class Solution {
public:
	bool backspaceCompare(string s, string t)
	{
		string res1;
		string res2;
		for (auto& k : s)
		{
			if (k == '#')
			{
				if (!res1.empty())
				{
					res1.pop_back();
				}
			}
			else
			{
				res1 += k;
			}
		}

		for (auto& k : t)
		{
			if (k == '#')
			{
				if (!res2.empty())
				{
					res2.pop_back();
				}
			}
			else
			{
				res2 += k;
			}
		}

		if (res1 == res2)
		{
			return true;
		}
		return false;
	}
};

1047. 删除字符串中的所有相邻重复项
class Solution
{
public:
	string removeDuplicates(string s)
	{
		string ret; // 搞⼀个数组，模拟栈结构即可
		for (auto ch : s)
		{
			if (ret.size() && ch == ret.back()) ret.pop_back(); // 出栈
			else ret += ch; // ⼊栈
		}
		return ret;
	}
};